<?php

class Silk_Zgb_Model_Manufacturer extends Mage_Core_Model_Abstract
{
    protected function _construct(){

       $this->_init("zgb/manufacturer");

    }

    public function toOptionArray()
    {
    	$resource = Mage::getSingleton('core/resource');
        $db = $resource->getConnection('core_read');
        $sql = "SELECT id,`name` FROM zgb_manufacturer WHERE 1 ORDER BY CONVERT( `name` USING gbk ) COLLATE gbk_chinese_ci ASC";
        $query = $db->query($sql);
        $_items = $query->fetchAll();

        $_options = array();
        foreach($_items as $_item)
        {
            $_options[] = array('value'=>$_item['id'],'label'=>$_item['name']);
        }
    	return $_options;
    }

    public function loadByAdminId($id)
    {
        $collection = $this->getCollection();
        $collection->addFieldToFilter('admin_id', array('eq'=>$id));
        return $collection->getFirstItem();
    }

}
	 